<?php
// 后台用户模块
class UserAction extends Action {

	public function Successs($message,$jumpUrl='',$status='1',$waitSecond='3'){
		if($jumpUrl){
			$this->assign('jumpUrl',$jumpUrl);//地址
		}else{
		$this->assign('jumpUrl','-1');
		}
		$this->assign('status',$status);   // 状态
		$this->assign('message',$message);// 提示信息
		$this->assign('waitSecond',$waitSecond);//跳转秒数
		$this->assign('waitSeconds',$waitSecond*1000);//跳转秒数
	        
		if($status==1)
		{
			$this->assign('msgTitle','成功');  
		}
		else 
		{
			$this->assign('msgTitle','失败');  
		}
		$this -> display('Public:success');
		exit();
	}
	
	public function Verify() {
//		ob_clean();  //关键代码，防止出现'图像因其本身有错无法显示'的问题。
//		Header("Content-type: image/PNG");
		import("ORG.Util.Image");
		Image::buildImageVerify(4,3,png,70,29,verify);
	}
	
	public function Adminlogin() {
		$this->display();
	}
	
	public function Adminlogins()
	{
		$check = $this->_post('checkout');
		$username = $this->_post('name');
		$password = $this->_post('pwd');
		$verify = $this->_post('code');
		$code = strtolower($verify);
		if($check==1){
			if($_SESSION['verify'] != md5($code)) {
	  			 echo '<meta http-equiv="Content-Type" content="txt/html; charset=utf-8" /><script>alert("请正确填写验证码");history.go(-1);</script>';
	 		} else {
	 			$users = M("web_user");
				$user = $users->where('username=\''.$username.'\'')->field('id,username,verify,nickname,salt,password,login_count')->find();
					if(md5(md5($password).sha1($user['salt'])) == $user['password']){
						$_SESSION[C('USER_AUTH_KEY')]	=	$user['id'];
						session('adminid',$user['id']);
						session('username',$user['username']);
						session('nickname',$user['nickname']);
						session('password',sha1($user['password'].$user['verify']));
						$data['login_count'] = $user['login_count']+1;
						$data['last_login_time'] = time();
						$data['last_login_ip'] = get_client_ip();
						 
						$info = 1;
					}else{
						$this->Successs('登陆失败,用户名或密码有误');
					}
					
				if($info==1){
					$this->Successs('登陆成功','/Admin/index.php/Index/Index',1,3);
				}
	 		}
		}else{
			$this->Successs('非法提交');
		}
	}
}
?>